﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// MainWindow 构造函数
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            this.Title = "我的WPF程序";
        }

        private void Open_new_Window_Click(object sender, RoutedEventArgs e)
        {
            // 打开新窗口
            Window1 newWindow = new Window1();
            newWindow.Show();
        }

        /// <summary>
        /// 处理按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            // 获取用户输入的姓名
            string name = NameTextBox.Text;
            // 判断姓名是否为空
            if (string.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show("请输入您的姓名！", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // 显示欢迎消息
            MessageBox.Show($"欢迎，{name}！", "欢迎", MessageBoxButton.OK, MessageBoxImage.Information);
        }

        /// <summary>
        /// 处理打开新窗口按钮的点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // 打开新窗口
            Window1 newWindow = new Window1();
            newWindow.Owner = this; // 设置当前窗口为新窗口的父窗口
            newWindow.Show();

            //newWindow.Topmost = true; // 设置新窗口为最上层窗口


        }

        /// <summary>
        /// 打开一个表单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenATable_Click(object sender, RoutedEventArgs e)
        {
            AFormTable1  newWindow = new AFormTable1();
            newWindow.Owner = this;
            newWindow.Show();
        }
    }
}